<?php
function search( $a, $target ) {
	$i = 0;
	$j = count( $a ) - 1;
	while ( $i<=$j ) {
		$k = floor( ( $i+$j )/2 );
		if ( $a[$k] == $target ) return $k;
		if ( $a[$k] >  $target ) $j = $k-1;
		if ( $a[$k] <  $target ) $i = $k+1;
	}
	return -1;
}

$a = range( 1,10 );
print_r( search( $a, 11 ) );
echo "\n";
